package project.servlet;

import project.bean.UserBean;
import project.dao.IUserDao;
import project.dao.impl.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class TestServlet extends HttpServlet {
        private IUserDao userDao=new UserDaoImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求编码集，只对post有效
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        //根据表单名的得到表单值
        String userName = req.getParameter("userName");
        String pwd = req.getParameter("pwd");
        UserBean login = userDao.login(userName, pwd);
            if (login==null){
                resp.getWriter().print("登录失败");
            }else {
                resp.getWriter().print("登录成功");
            }
    }
}
